<?php
/**
 * Created by PhpStorm.
 * User: hisheng
 * Date: 2017/6/5
 * Time: 17:59
 */
namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller ;
use App\Loan;
use Illuminate\Support\Facades\Config;

class LoanController extends Controller
{
    public $loan;
    public function __construct(Loan $loan)
    {
        $this->loan = $loan;
    }
    
    public function index(){
        $loan = $this->loan->orderBy('updated_at','desc')->where('is_delete',0)->paginate(10);
        $loans = [];
        if($loan){
            $loans =  $loan->toArray();
            $loans['data'] = $this->originIcon($loans['data']);
        }
        return $this->json($loans);
    }
    
    public function detail($id){
        $loan = $this->loan->find($id);
        if($loan){
            if($loan->icon){
                $loan->icon = Config::get('app.www_host'). $loan->icon;
            }
            return $this->json($loan);
        }
        return $this->error('没有此商品');
    }
}